package com.andrew.common;

import java.io.Serializable;
import java.util.HashMap;

public class ReturnResult<T> implements Serializable {
    private static final long serialVersionUID = -4696008537295855861L;

	private Integer code;
	private String message;
	private T data;

    public static <T> ReturnResult<T> withSuccess(T data) {
        return new ReturnResult<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(), data);
    }

	public static <T> ReturnResult<T> withSuccess() {
		return new ReturnResult(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(), new HashMap<>());
	}

    public static <T> ReturnResult<T> withFailed(T data) {
        return new ReturnResult<>(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getMsg(), data);
    }

	public static <T> ReturnResult<T> withFailed() {
		return new ReturnResult(ResponseCode.ERROR.getCode(), ResponseCode.ERROR.getMsg(), new HashMap<>());
	}

    public static <T> ReturnResult<T> withNormal(Integer code, String message, T data) {
        return new ReturnResult<>(code, message, data);
    }

	public static <T> ReturnResult<T> withNormal(Integer code, String message) {
		return new ReturnResult(code, message, new HashMap<>());
	}

    public ReturnResult() {
    }

    public ReturnResult(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Integer getCode() {
		return code;
	}
	public void setCode(Integer code) {
		this.code = code;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	
}
